package com.itheima.a06anno;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyAnnoDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {
        //1.获取MyTestDemo这个类的字节码文件对象
        Class<?> clazz = Class.forName("com.itheima.a06anno.MyTestDemo");

        //补一个类
        MyTestDemo mtd = new MyTestDemo();

        //2.获取里面所有的方法
        Method[] methods = clazz.getDeclaredMethods();

        //3.遍历得到每一个方法
        for (Method method : methods) {
            //4.临时修改一下权限
            method.setAccessible(true);
            //5.判断当前方法上面有没有MyTest注解
            if(method.isAnnotationPresent(MyTest.class)){
                method.invoke(mtd);
            }
        }
    }
}
